<?

for($iRow = 0; $iRow <= $_SESSION["init_num"]; $iRow++){

	//if everything is ok than upload
	if($_POST["unitEnt"][$iRow]     != '' &&
	   $_POST["qtyEnt"][$iRow]      != '' &&
	   $_POST["cvtQtyEnt"][$iRow]   != '' &&
	   $_POST["priceEnt"][$iRow]    != '' &&
	   $_POST["hrzTotEnt"][$iRow]   != ''){

		//upload
		$dataup++;

	}else
	if($_POST["unitEnt"][$iRow]     == '' &&
	   $_POST["qtyEnt"][$iRow]      == '' &&
	   $_POST["cvtQtyEnt"][$iRow]   == '' &&
	   $_POST["priceEnt"][$iRow]    == '' &&
	   $_POST["hrzTotEnt"][$iRow]   == ''){

		//mark end of record	if it reaches max sort
		for($i2Row=$iRow; $i2Row <= $_SESSION["init_num"]; $i2Row++){

			//continue to make sure no jump blank row
			//if found one then error and restore
			//echo	"<br/>\$_POST[\"item_grade_ent\"][$icc] :" .$_POST["item_grade_ent"][$icc];
			if($_POST["unitEnt"][$i2Row]     != '' &&
    	   $_POST["qtyEnt"][$i2Row]      != '' &&
    	   $_POST["cvtEnt"][$i2Row]      != '' &&
    	   $_POST["cvtQtyEnt"][$i2Row]   != '' &&
    	   $_POST["priceEnt"][$i2Row]    != '' &&
    	   $_POST["hrzTotEnt"][$i2Row]   != ''){

				/**
				* raise error
				*
				*/
				$err = $i2Row + 1;

				usrError("ERROR: No empty field allowed please make a correction reason: record ".$err." ");

				$err     = 0;
				$restore = 1;
				break;
			}
		}

		if($restore != 1){

			$uprun = 1;
			break;
		}
	}else{

		/**
		* Error!! cant continue some of the field(s) is blank and
		* tell what line which caused this
		*
		*/
		$err = $iRow + 1;

		usrError("ERROR: No empty field allowed please make a correction reason: record ".$err." ");

		/**
		* put back everything
		*
		*/
		$err = 0;
		$restore = 1;

		break;
	}
}

if($dataup == 0 ){

	usrError("ERROR: Data is empty");

	jumpTo(2,"../".$_SESSION["source_caller"]);
}

if($uprun == 1 && $dataup > 0){

	/**
	* We are good with details
	* continue with the header check
	*
	*/
	if($_POST["trDateEnt"] != ''    &&
	   $_POST["supplierEnt"]!= ''   &&
	   $_POST["currencyEnt"] != ''  &&
	   $_POST["rateEnt"] != ''      &&
	   $_POST["memoEnt"] != ''){

		//everything is good
		//open confirmation form
		if(!$_POST["confirm"] && !$_POST["back"]){

			require("entry_upload_confirm.php");
		}elseif($_POST["back"]){

			require("entry_restore_me.php");
		}else{

			/**
			* Prepare to upload
			* modify mode is on
			*
			*/
			if($_SESSION["modify_mode"] == "Y" && $_SESSION["jid"] != ''){

				/**
				* Reset the modify_mode
				*
				*/
				$_SESSION["modify_mode"] = "N";

				require("upmodifytodb.php");
			}elseif($_SESSION["modify_mode"] != "Y"){ //if modify mode is off

				require("upentrytodb.php");
			}else{

				echo "Unknown Upload Task!!!\n";
			}
		}
	}else{

		usrError("Error:  No empty field allowed please make a correction reason: header incompleted");

		require("entry_restore_me.php");
	}
}

if($restore == 1){

	echo "Restoring...\n";
	$restore  = 0;
	$uprun    = 0;
	$dataup   = 0;

	require("entry_restore_me.php");
}
?>